package com.yanqu.road.server.cmd.activity.wealthscroll;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.WealthScrollProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.WealthScrollModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_WEALTH_SCROLL_GET_USER_DATA,desc = "新财神密卷获取玩家数据")
public class WealthScrollGetUserDataCmd extends AbstractCommand {

    private int activityId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        WealthScrollProto.WealthScrollGetUserDataReq req = WealthScrollProto.WealthScrollGetUserDataReq.parseFrom(packet.getBytes());
        activityId = req.getActivityId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(WealthScrollModule.class).getUserDataMsg(activityId);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0){
            WealthScrollProto.WealthScrollGetUserDataResp.Builder resp = WealthScrollProto.WealthScrollGetUserDataResp.newBuilder();
            resp.setRet(ret);
            player.sendPacket(ClientProtocol.U_WEALTH_SCROLL_GET_USER_DATA, resp);
        }
    }
}
